// pages/category/index.js
// import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog.js'
// import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    loading1: false,  // 加载状态
    noMore: false,   // 是否无更多数据
    lastDoc: null,    // 最后一条文档（用于分页）
    baseId:'',
    isButtonExpanded:false,
    baseAvatarUrl:'',
    baseNickName:'',
    isSelf:true,
    chooseOpenid:'',
    showPopup: false,
    shuffledAvatars: [], // 弹窗内随机分布的头像
    avatarList:[],
    inviterCode:'',
    shareType:'normal',
    carCount:0,
    carObj:{},
    isLoggedIn:false,
    userInfo:{},
    statusList:[],
    text:'修改',
    showTip:'',
    showType:'',
    countNum:0,
    selectType:[],
    selectFood:[], // 选中的所有菜谱
    activeIndex: null, // 当前选中的分类索引
    activeId:'',
    activeName:'',
    categories: [], // 分类数据
    loading: true, // 加载状态
    scrollTop: 0, // 滚动位置
    priceArr:[5,10,15,20,25,30],
    editing:false, 
    showDialog:false,
    goodsId:0,
    newPrice: '', // 存储输入的新价格
    selectIndex:0,
    showDialog1:false,
    db:null,
  },
  onShareAppMessage() {
    return this.data.shareType === 'normal' ? {
      title: '这是我的电子菜谱，快来围观吧！',
      path: '/pages/login/index', // 携带邀请人ID
      imageUrl: '/images/business/bg.png',
      // imageUrl: 'https://636c-cloud1-4gksk5gzbfe188ed-1258156349.tcb.qcloud.la/recipe-images/1753411154262-45549.jpg?sign=3c9a1e3a16855318f1c157500bf1c793&t=1753411157' // 自定义图片URL
    } : {
      title: '这是我的厨房，快来下单吧！',
      path: `/pages/login/index?interver=${this.data.userInfo.nameCode}`, // 携带邀请人ID
      imageUrl: '/images/usercenter/bg.png',
      // imageUrl: 'https://636c-cloud1-4gksk5gzbfe188ed-1258156349.tcb.qcloud.la/recipe-images/1753411154262-45549.jpg?sign=3c9a1e3a16855318f1c157500bf1c793&t=1753411157' // 自定义图片URL
    }
  },
  onShow() {
    const userInfo = wx.getStorageSync('userInfo');
    console.log('business userInfo',userInfo)
    this.setData({
      isLoggedIn: !!userInfo,
      userInfo: userInfo || {},
    });
    console.log('business onShow',this.data.carObj,this.data.avatarList)
    // this.getInitData()

    let newAvatarList = JSON.parse(JSON.stringify(this.data.avatarList))
    newAvatarList[0] = {
      nickName:'我',
      nameCode:this.data.userInfo.nameCode,
      _openid:this.data.userInfo._openid,
      userId:this.data.userInfo.userId,
      avatarUrl:this.data.userInfo.avatarUrl,
    }
    console.log('newAvatarList',this.data.userInfo.nickName,newAvatarList)
    this.setData({
      avatarList:newAvatarList
    })
    this.refresh()
  },
  onLoad() {
    console.log('business onLoad')
    this.getInitData()
  },
  refresh(){
    const app = getApp()
    console.log('app.globalData',app.globalData)
    if(!app.globalData.detail){
      console.log('onshow no detail')
      this.setData({
        carObj:{},
        carCount:0
      })
    }
    if(app.globalData.refreshId){
      console.log('this.data.activeId',this.data.activeId,app.globalData.refreshId)
      if(this.data.activeId === app.globalData.refreshId){
        this.loadCategoryData(app.globalData.refreshId,true)
      }
      delete app.globalData.refreshId
    }
    if(app.globalData.refreshType){
      this.getTypeList()
      delete app.globalData.refreshType
    }else{
      this.getShowTip()
    }

  },
  getInitData(){
    this.setData({ loading: true});
    const inviterCode = wx.getStorageSync('inviterCode')
    this.setData({
      inviterCode:inviterCode
    })
    const userInfo = wx.getStorageSync('userInfo');
    console.log('business userInfo',userInfo)
    this.setData({
      isLoggedIn: !!userInfo,
      userInfo: userInfo || {},
    });
    this.setData({
      chooseOpenid:this.data.userInfo._openid
    });

    // 在任何页面/组件中获取
    const app = getApp();
    console.log(app.globalData.env); // 输出: your-env-id
    // 获取默认环境的数据库引用
    this.setData({
      db:app.globalData.db
    })
    this.setData({
      avatarList:[]
    })
    const me = {
      nickName:'我',
      nameCode:this.data.userInfo.nameCode,
      _openid:this.data.userInfo._openid,
      userId:this.data.userInfo.userId,
      avatarUrl:this.data.userInfo.avatarUrl,
    }
    const newArr = JSON.parse(JSON.stringify(this.data.avatarList))
    newArr.push(me)
    this.setData({
      avatarList:[...newArr]
    })
    // wx.setStorageSync('avatarList', this.data.avatarList)
    const _ = this.data.db.command // 获取数据库命令构造器
    this.data.db.collection('newsList').where(
      _.and([
        _.or([
          { receiverId: this.data.userInfo._openid }, // 条件1: a 字段等于 openid
          // { _openid: this.data.userInfo._openid }  // 条件2: b 字段等于 openid
        ]),
        { isRead: false } // 条件3: isRead 必须为 false
      ])
    ).get()
    .then(res => {
      if(res && res.data && res.data.length > 0){
        wx.setTabBarBadge({
          index: 3,
          text: res.data.length + ''
        });
      }else{
        wx.removeTabBarBadge({
          index: 2,
        });
      }
    })
    this.data.db.collection('statusList').where({}).get()
    .then(res => {
      console.log('res',res)
      if(res && res.data && res.data.length > 0){
        this.setData({
          statusList:res.data
        })
      }else{
        this.setData({
          statusList:[]
        })
      }
    })
    // 获取指定集合的引用
    // const collection = db.collection('type')
    // console.log('collection',__wxConfig.envVersion,collection)
    console.log('this.data.db.collection(nviterList)',this.data.carObj)
    this.data.db.collection('inviterList')
    .where({
      beiInterver:this.data.userInfo.nameCode
    })
    .get()
    .then(res => {
      const newArr1 = JSON.parse(JSON.stringify(this.data.avatarList))
      newArr1.splice(1)
      this.setData({
        avatarList:newArr1
      })
      console.log('inviterList res',res,this.data.avatarList)
      if(res && res.data && res.data.length > 0){
        const newArray = res.data.map(item => ({
          nickName: item.interver_nickName,
          _openid: item.interver__openid,
          userId: item.interver_userId,
          avatarUrl: item.interver_avatarUrl,
          nameCode: item.interver
        }));
        console.log('newArray',newArray,this.data.avatarList)
        this.setData({
          avatarList:[...this.data.avatarList,...newArray]
        })
      }
    })
    .catch(err => {

    })
    .finally(() => {
      this.getTypeList()
    })

    // 传递：
    // wx.navigateTo({
    //   url: `/pages/detail/detail?id=${id}&time=${Date.now()}` // 防缓存
    // })
    // 接收：
    // onLoad(options) {
    //   this.setData({ 
    //     id: parseInt(options.id), // 转数字类型
    //     timestamp: options.time 
    //   })
    // }
    // this.loadCategoryData();
  },
  getTypeList(type){
    const app = getApp();
    console.log('getTypeList app.globalData',app.globalData)
    if(app.globalData.chooseChef){
      const chooseChef = JSON.parse(decodeURIComponent(app.globalData.chooseChef))
        console.log('getTypeList chooseOpenid 111',this.data.chooseOpenid,chooseChef._openid)
        if(type === 'change' && this.data.chooseOpenid === chooseChef._openid)return;
        this.setData({
          chooseOpenid:chooseChef._openid,
          noMore:false,
        })
    }
    console.log('to get type list',app.globalData)
    this.getShowTip()
    if(this.data.chooseOpenid === this.data.userInfo._openid){
      this.setData({
        isSelf:true
      })
    }else{
      this.setData({
        isSelf:false
      })
    }
    this.data.db.collection('type')
    .orderBy('order','asc')
    .where({
      _openid:this.data.chooseOpenid
    })
    .get()
    .then(res => {
      console.log('res type collpe',res)
      if(res && res.data && res.data.length > 0){
        this.setData({
          selectType:res.data,
        })
        console.log('app.globalData',app.globalData)
        if(!app.globalData.detail){
          console.log('onshow no detail')
          this.setData({
            carObj:{},
            carCount:0
          })
        }
        console.log('this.data.carObj',this.data.carObj,this.data.carCount)
        console.log('this.data.selectType',this.data.selectType,app.globalData.activeId)
        if (app.globalData.activeId) {
          const index = this.data.selectType.findIndex(item => item._id === app.globalData.activeId);
          console.log('app.globalData.activeId',app.globalData.activeId,index)
          this.setData({
            activeId:res.data[index]._id,
            activeIndex:index,
            activeName:res.data[index].name
          })
          delete app.globalData.activeId // 使用后清除
          this.loadCategoryData(res.data[index]._id,true)
        }else{
          this.setData({
            activeId:res.data[0]._id,
            activeIndex:0,
            activeName:res.data[0].name
          })
          this.loadCategoryData(res.data[0]._id,true)
        }
        // this.getCountNum()

      }else{
        this.setData({
          activeId:'',
          activeIndex:null,
          activeName:'暂无分类',
          selectType:[],
          categories:[],
          loading: false,
          countNum:0
        })
        wx.showToast({ title: '加载分类数据为空', icon: 'none' })
      }
      // this.setData({ todos: res.data })
      // wx.hideLoading()
    })
    .catch(err => {
      wx.showToast({ title: '加载分类数据失败', icon: 'none' })
      this.setData({ selectType:[],loading: false });
    })
  },
  getCountNum(){
    const arr = this.data.selectType.map(item => item._id)
    console.log('arr',arr)
    this.data.db.collection('message')
    .where({
      _openid:this.data.chooseOpenid
    })
    .get()
    .then(res => {
      console.log('res getCountNum',res)
      if(res && res.data && res.data.length > 0){
        const result = res.data.filter(item => arr.includes(item.typeId));
        this.setData({
          countNum:result.length
        })
      }
    })
  },
    // 滚动到底部触发
    onScrollToLower() {
    this.loadCategoryData(this.data.baseId)
  },
  // 加载分类数据
  loadCategoryData(_id,init=false) {
    console.log('loadCategoryData this.data.loading1',this.data.loading1,this.data.noMore)
    if (this.data.loading1 || this.data.noMore) return
    
    this.setData({ loading1: true })
    wx.showLoading({ title: '加载中...' })

    this.setData({
      baseId:_id
    })
    this.data.db.collection('message')
    .where({
      typeId: _id,
      // _openid:this.data.userInfo._openid
    })
    .orderBy('createTime', 'desc')
    .skip(init ? 0 : this.data.categories.length) // 跳过已加载数据
    .limit(20) // 每次20条
    .get()
    .then(res => {
      console.log('res loadCategoryData',res,_id)
      if(res && res.data && res.data.length > 0){
        for(let key in res.data){
          res.data[key].num = 0
        }
        this.setData({
          categories: init ? res.data : [...this.data.categories, ...res.data],
          loading: false,
          noMore: res.data.length < 20,
          lastDoc: res.data[res.data.length - 1] // 记录最后一条
        });
      }else{
        // wx.showToast({ title: '加载数据为空', icon: 'none' })
        this.setData({ 
          categories:[],
          loading: false
         });
      }
      // this.setData({ todos: res.data })
      // wx.hideLoading()
    })
    .catch(err => {
      wx.showToast({ title: '加载数据失败', icon: 'none' })
      this.setData({ 
        categories:[],
        loading: false,
       });
    })
    .finally(() => {
      this.setData({ loading1: false })
      wx.hideLoading()
    }) 
    return;
    this.setData({ loading: true });
    

    // 模拟API请求
    setTimeout(() => {
      const mockData = this.generateMockData();
      this.setData({
        categories: mockData,
        loading: false
      });
      console.log('mockData',mockData)
    }, 800);
  },

  // 生成模拟数据
  generateMockData() {
    const categoryNames = [
      '美食', '快餐便当', '特色菜系', '甜品饮品', 
      '超市便利', '水果蔬菜', '鲜花绿植', '医药健康'
    ];
    
    return categoryNames.map((name, index) => {
      // const subCategories = Array.from({ length: Math.floor(Math.random() * 5) + 5 }, (_, i) => ({
      const subCategories = {
        id: `sub_${index}`,
        name: `${name}子类`,
        goods: Array.from({ length: Math.floor(Math.random() * 8) + 3 }, (_, j) => ({
          id: `goods_${index}_${j}`,
          name: `${name}商品${j+1}`,
          num:0,
          count:999,
          price: this.data.priceArr[Number(Math.floor(Math.random() * 6))],
          rate: Math.ceil(Math.random() * 5),
          image: `https://picsum.photos/200/200?random=${index}0${j}`
        }))
      }
      // }));
      
      return {
        id: `cat_${index}`,
        name,
        subCategories
      };
    });
  },

  // 切换分类
  onChange(event) {
    const index = event.detail;
    console.log('index',index)
    this.setData({
      activeName:this.data.selectType[index].name,
      activeIndex: index,
      activeId:this.data.selectType[index]._id,
      scrollTop: 0, // 切换分类时滚动到顶部
      loading1: false,  // 加载状态
      noMore: false,   // 是否无更多数据
      lastDoc: null,    // 最后一条文档（用于分页）
    });
    this.loadCategoryData(this.data.selectType[index]._id,true)
  },

  // 跳转到商品详情
  goToGoodsDetail(e) {
    this.setData({
      goodsId:e.currentTarget.dataset.id
    })
    wx.navigateTo({
      url: `/pages/goods/detail?id=${this.goodsId}`
    });
  },

  // 跳转到子分类页面
  goToSubCategory(e) {
    const subId = e.currentTarget.dataset.id;
    const subName = e.currentTarget.dataset.name;
    wx.navigateTo({
      url: `/pages/category/sub?id=${subId}&name=${subName}`
    });
  },
  reduceFun(e){
    const id = e.currentTarget.dataset.id;
    const name = e.currentTarget.dataset.name;
    const price = e.currentTarget.dataset.price;
    const image = e.currentTarget.dataset.image;
    // this.setData({
    //   [`categories[${index}].num`]: this.data.categories[index].num - 1
    // });
    this.checkNum(id,name,price,image,'reduce')
  },
  addFun(e){
    const id = e.currentTarget.dataset.id;
    const name = e.currentTarget.dataset.name;
    const price = e.currentTarget.dataset.price;
    const image = e.currentTarget.dataset.image;
    // this.setData({
    //   [`categories[${index}].num`]: this.data.categories[index].num + 1
    // });
    this.checkNum(id,name,price,image,'add')
    return;

    const food = e.currentTarget.dataset.query;
    food.num = 1;
    console.log(food)
    const has = this.data.selectFood.filter(item => {
      item.id === food.id
    })
    const existingIndex = this.data.selectFood.findIndex(item => item.id === food.id); // 查找是否已存在相同 id

    if (existingIndex !== -1) {
      // 如果已存在，则 num + 1
      const updatedArray = this.data.selectFood.map((item, index) => {
        if (index === existingIndex) {
          return { ...item, num: item.num + 1 }; // 使用扩展运算符更新 num
        }
        return item;
      });
      this.setData({ selectFood: updatedArray });
    } else {
      // 如果不存在，则新增到数组
      this.setData({ 
        selectFood: [...this.data.selectFood, food],
      });
    }
    console.log(this.data.selectFood)
  },
  checkNum(id,name,price,image,type){
    console.log('this.data.carObj',this.data.carObj)
    // 检查对象中是否已存在该ID
    if (this.data.carObj.hasOwnProperty(id)) {
      // 如果存在，计数加1
      if(type === 'add'){
        this.setData({
          [`carObj.${id}.num`]: this.data.carObj[id].num + 1
        })
      }else{
        if( this.data.carObj[id].num === 1){
          // 1. 先创建一个新对象（避免直接修改原对象）
          const newCarObj = { ...this.data.carObj };

          // 2. 删除指定 id 属性
          delete newCarObj[id];

          // 3. 更新数据
          this.setData({
            carObj: newCarObj
          });
        }else{
          this.setData({
            [`carObj.${id}.num`]: this.data.carObj[id].num - 1
          })
        }
      }
    } else {
      if(type === 'add'){
        this.setData({
          [`carObj.${id}`]: {
            ...this.data.carObj[id], // 保留原有属性
            num: 1,                  // 设置/覆盖 num
            name: name,        // 添加新属性
            price: price,    // 添加另一个新属性
            image:image,
            _id:id
          }
        })
      }
    }

    let count = 0;
    for(let key in this.data.carObj){
      count += this.data.carObj[key].num
    }
    this.setData({
      carCount:count
    })
  },
  addCaipu(){
    wx.navigateTo({ url:`/pages/add/index?types=add&activeId=${this.data.activeId}&time=${Date.now()}`});
  },
  quitFun(){
    this.setData({
      editing:false
    })
  },
  setEditing(){
    this.setData({
      editing:true
    })
  },
  onClose() {
    console.log('onClose')
    // this.setData({ showDialog: false });
  },
  onConfirm(){
    console.log('onConfirm sss',this.data.newPrice)
     // 检查是否只包含数字
     if(this.data.newPrice === ''){
      wx.showToast({ title: this.data.showTip, icon: 'none' });
      return;
     }
     if (/^\d*$/.test(this.data.newPrice)) {
      this.submitForm();
    } else {
      wx.showToast({ title: `请输入合理的${this.data.showTip}`, icon: 'none' });
    }
  },
  onCancel(){
    console.log('onCancel')
    this.setData({ showDialog: false });
  },
  submitForm(){
    wx.showLoading({
      title: '修改中...',
    })
    const data ={}
    if(this.data.showType === 'price'){
      data.price = this.data.newPrice
    }else if(this.data.showType === 'count'){
      data.count = this.data.newPrice
    }
    this.data.db.collection('message').doc(this.data.categories[this.data.selectIndex]._id).update({
      data: data,
      success: res => {
        wx.showToast({
          title: '修改成功',
          icon: 'none'
        })
        wx.hideLoading()
        if(this.data.showType === 'price'){
          this.setData({
            [`categories[${this.data.selectIndex}].price`]: this.data.newPrice
          });
        }else if(this.data.showType === 'count'){
          this.setData({
            [`categories[${this.data.selectIndex}].count`]: this.data.newPrice
          });
        }

      },
      fail: err => {
        wx.hideLoading()
        wx.showToast({
          title: '修改失败',
          icon: 'none'
        })
      }
    })
    // 验证通过，手动关闭对话框
    this.setData({ showDialog: false });
  },
  onInputChange(event){
    console.log('onInputChange',event.detail)
    this.setData({
      newPrice:event.detail
    })
    console.log('onInputChange newPrice',this.data.newPrice)
  },
  changeCount(e){
    if(!this.data.editing)return;
    this.setData({
      newPrice:e.currentTarget.dataset.price,
      showTip:'菜品库存',
      showType:'count',
      showDialog:true,
      goodsId:e.currentTarget.dataset.id,
      selectIndex:e.currentTarget.dataset.index
    })
  },
  changePrice(e){
    if(!this.data.editing)return;
    this.setData({
      newPrice:e.currentTarget.dataset.price,
      showTip:'菜品价格',
      showType:'price',
      showDialog:true,
      goodsId:e.currentTarget.dataset.id,
      selectIndex:e.currentTarget.dataset.index
    })
  },
  editFun(e){
    wx.navigateTo({ url:`/pages/add/index?types=edit&id=${e.currentTarget.dataset.id}&activeId=${this.data.activeId}&time=${Date.now()}` });
  },
  deleteFun(e){
    this.setData({
      showDialog1:true,
      goodsId:e.currentTarget.dataset.id,
      selectIndex:e.currentTarget.dataset.index
    })
  },
  close(){
    this.setData({
      showDialog1:false
    })
  },
  yesToDel(){
    wx.showLoading({
      title: '删除中...',
    })
    this.data.db.collection('message').doc(this.data.categories[this.data.selectIndex]._id).remove({
      success: res => {
        wx.hideLoading()
        wx.showToast({
          title: '删除成功',
          icon: 'none'
        })
        // 1. 获取当前数据数组
        let list =this.data.categories
        console.log('list top',list)
        // 2. 使用splice删除指定索引的元素
        list.splice(this.data.selectIndex, 1) // 从index位置开始删除1个元素
        console.log('list down',list)
        // 3. 更新数据
        this.setData({
          [`categories`]: list,
          showDialog1:false
        })
      },
      fail: err => {
        wx.hideLoading()
        wx.showToast({
          title: '删除失败',
          icon: 'none'
        })
      }
    })
  },
  typeEditFun(){
    wx.navigateTo({
      url: `/pages/type/index?activeId=${this.data.activeId}&time=${Date.now()}`
    });
  },
  showFun(e){
    console.log('showFun e',e)
    wx.navigateTo({ url:`/pages/show/index?types=show&id=${e.currentTarget.dataset.id}` });
  },
  normalShare(){
    this.setData({
      shareType:'normal'
    })
  },
  interverFun(){
    this.setData({
      shareType:'interver'
    })
  },
  toBuyFun(){
    if(this.data.carCount === 0)return;
    console.log('this.data.carObj',this.data.carObj,this.data.baseNickName,this.data.baseAvatarUrl,this.data.chooseOpenid,this.data.activeId)
    const detail = Object.values(this.data.carObj);
    console.log('detail',detail)
    const allDetail = {
      goodsList:detail,
      cheferId:this.data.chooseOpenid,
      cheferName:this.data.baseNickName,
      cheferAvatarUrl:this.data.baseAvatarUrl,
    }
    // 在任何页面/组件中获取
    const app = getApp();
    app.globalData.detail = encodeURIComponent(JSON.stringify(allDetail));
    wx.navigateTo({
      url: `/pages/detail/index?detail=${encodeURIComponent(JSON.stringify(allDetail))}&activeId=${this.data.activeId}&time=${Date.now()}`,
    });
  },
  
  // 动态计算分层和位置
  generateConcentricCircles(avatars) {
    const center = { x: 50, y: 50 }; // 中心点坐标（百分比）

    // 动态分层算法
    const layers = this.autoGenerateLayers(avatars.length);
    let positionedAvatars = [];
    let avatarIndex = 0;

    layers.forEach((layer, layerIndex) => {
      const angleStep = (2 * Math.PI) / layer.count;
      
      for (let i = 0; i < layer.count && avatarIndex < avatars.length; i++) {
        const angle = angleStep * i;
        positionedAvatars.push({
          ...avatars[avatarIndex],
          left: center.x + layer.radius * Math.cos(angle) + '%',
          top: center.y + layer.radius * Math.sin(angle) + '%'
        });
        avatarIndex++;
      }
    });

    return positionedAvatars;
  },

  // 动态分层算法（核心）
  autoGenerateLayers(avatarCount) {
    const layers = [];
    let remaining = avatarCount;
    let radius = 15; // 第一层基础半径
    let layerCount = 4; // 第一层基础数量

    while (remaining > 0) {
      const count = Math.min(layerCount, remaining);
      layers.push({ 
        radius: radius + (layers.length * 20), // 每层半径递增
        count 
      });
      layerCount += 4; // 每层数量递增
      remaining -= count;
    }

    return layers;
  },
  showAvatarPopup() {
    this.setData({
      showPopup: true,
      shuffledAvatars: this.generateConcentricCircles(this.data.avatarList)
    });
  },
  
  hidePopup() {
    this.setData({ showPopup: false });
  },
  handleAvatarClick(e) {
    const user = e.currentTarget.dataset.user;
    console.log('点击的头像数据:', user);
  
    wx.showToast({
      title: `选中用户: ${user.nickName}`,
      icon: 'none'
    });
    const app = getApp();
    app.globalData.chooseChef = encodeURIComponent(JSON.stringify(user));
    this.setData({
        activeIndex:0,
        activeName:'',
        carObj:{},
        carCount:0,
    })
    this.getTypeList('change')
    // 可以在这里跳转到用户详情页，或执行其他逻辑
    // wx.navigateTo({ url: `/pages/user/user?id=${user.userid}` });
  },
  getShowTip(){
    const arr = this.data.avatarList.filter(item => item._openid === this.data.chooseOpenid)
    console.log('getShowAvatarUrl',arr)
    if(arr && arr.length > 0){
      this.setData({
        baseAvatarUrl:arr[0].avatarUrl || '',
        baseNickName:arr[0].nickName
      })
    }
  },
   // 切换按钮状态
   toggleButton() {
    if (this.data.isButtonExpanded) {
      // 如果按钮已经展开，打开弹窗
      this.showAvatarPopup()
    } else {
      // 如果按钮未展开，先展开按钮
      this.setData({
        isButtonExpanded: true
      });
    }
  },
  hideButton(){
    console.log('hideButton',this.data.isButtonExpanded)
    this.setData({
      isButtonExpanded:false
    })
  }
});